from LoadLib import *

#def dem1(p):
#    return lambda p: C(teeth(p.x * 5), 0, 0)

#def dem2(p):
#    lambda p: C(teeth(p.x*4),0,  teeth(p.x * 2))

#def polarMask(p):
#    (r, theta) = toPolar(p)
#    return 


whiteI = lambda p: white
blackI= lambda p: black
greenI = lambda p: C(0,1,0)

parker1 = mask(lambda p: abs(p) < .5, whiteI, blackI)

def parker(image1, image2):
    return mask(teethMask, image1, image2)


zoom = lambda z: lambda p: p/z

def parker2(image1, image2):
    return mask(lambda p: abs(p) < .5, image1 ,image2)

def parker3(image1, image2):
    return blend(lambda p: ramp(p.x +.5), image1, image2)

def lens(p):
	(r, theta) = toPolar(p) 
	return fromPolar(r * r, theta)


def lense(image):
    return lambda p: image(P2(p.x, p.y *p.x))

def teethMask(p):
    return p.y < (teeth(p.x * 10) * .2) -.1

parker2 = mask(teethMask, whiteI, blackI)

#def park3(image):
#    return lambda p: image(P2(teeth(p.x * 2), p.y * p.y))

#def park2(p):
#    return C(teeth(p.x * 3), frac(p.y), p.x * p.x)

def park1(p):
    (r, theta) = toPolar(p)
    return togrey(teeth(10*r))

def tile(x):
       return lambda p: P2(frac(x*p.x), frac(x*p.y))

shift = lambda d: lambda p: p - d

#def zoom(image, int):
#   return lambda p:image(P2(p.x / int, p.y / int))  

def kal(n):
    def lens(p):
        (r, theta) = toPolar(p)
        #return fromPolar(r, 2* 3.14159* ( -.5 + teeth(n*(.5 + theta/(2 *3.14159)))))
        return fromPolar(r, theta * n)
    return lens